<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace console\controllers;

use common\models\ParkCurrent;
use common\models\ParkCurrentSpace;
use common\models\ParkSpace;
use yii\console\Controller;

class DemoController extends Controller
{

    public function actionInit()
    {
            $ps = new ParkSpace([
                'uid' =>'3768255b-844e-4e0d-94f4-f4da585a295b',
                'sn' => '车位编号1',
                'name' => '车位编号1',
                'loc_id' => 1,
                'hw_id' => 'hw1',
                'status' => '1'
            ]);
            $ps->save();
        $pc = new ParkCurrent(
            [
                'id'=>'0104745d-8a5b-11e7-a128-005056c00008',
                'start_time'=>'2017-08-25 10:00'
            ] );
        $pc->save();

        $pcs = new ParkCurrentSpace([
            [
                'id'=>'9c0a7c7a-8a5c-11e7-a128-005056c00008',
                'park_current_id'=>'0104745d-8a5b-11e7-a128-005056c00008',
                'park_space_id'=>'3768255b-844e-4e0d-94f4-f4da585a295b'
            ]
        ]);
        $pcs->save();



    }


    public function actionPark()
    {
        $hw ='hw1';
        $check =  (new \yii\db\Query())
            ->select(['count'=>'count(*)'])
            ->from('park_current_space pcs')
            ->innerJoin('park_space ps', 'pcs.park_space_id = ps.uid')
            ->where(['ps.hw_id'=> $hw])
            ->one();
        if($check && $check['count'] > 0)
        {
            echo $check['count'];
        }
        else
        {
            $parkSpace = ParkSpace::findOne(['hw_id'=>$hw]);
            $pc = new ParkCurrent([
                'id'=>\thamtech\uuid\helpers\UuidHelper::uuid(),
                '$start_time'=>date()
            ]);
            $pc->save();
        }



    }


    public function actionPay()
    {

    }


}
